package cn.itcast.shop.order.service;

import java.util.List;

import org.springframework.transaction.annotation.Transactional;

import cn.itcast.shop.categorysecond.vo.CategorySecond;
import cn.itcast.shop.order.dao.OrdersDao;
import cn.itcast.shop.order.vo.OrderItem;
import cn.itcast.shop.order.vo.Orders;
import cn.itcast.shop.utils.PageBean;

@Transactional
public class OrdersService {
	private OrdersDao ordersDao;

	public void setOrdersDao(OrdersDao ordersDao) {
		this.ordersDao = ordersDao;
	}

	public void saveOrder(Orders order) {
		ordersDao.saveOrder(order);
	}

	/**
	 * 
	 * @param uid
	 * @param page
	 * @return
	 */
	public PageBean<Orders> findByPageUid(Integer uid,Integer page) {
		PageBean<Orders> pageBean = new PageBean<Orders>();
		//设置当前页数：
		pageBean.setPage(page);
		//设置每页显示的记录数
		Integer limit = 5;
		Integer totalCount = 0;
		pageBean.setLimit(limit);
		totalCount = ordersDao.findByCountUid(uid);
		pageBean.setTotalCount(totalCount);
		List<Orders> list = ordersDao.findByPageUid(uid,pageBean.getBegin(),limit);
		pageBean.setList(list);
		return pageBean;
	}

	public Orders findByOid(Integer oid) {
		return ordersDao.findByOid(oid);
	}
	
	/**
	 * 更新订单信息
	 * @param currOrder
	 */
	public void update(Orders currOrder) {
		ordersDao.update(currOrder);
	}

	public PageBean<Orders> findByPage(Integer page) {
		PageBean<Orders> pageBean = new PageBean<Orders>();
		
		Integer limit = 10;
		pageBean.setLimit(limit);
		pageBean.setPage(page);
		int totalCount = ordersDao.findCount();
		pageBean.setTotalCount(totalCount);
		List<Orders> list =ordersDao.findByPage(pageBean.getBegin(),limit);
		pageBean.setList(list);
		
		return pageBean;
	}

	public List<OrderItem> findOrderItem(Integer oid) {
		return ordersDao.findOrderItem(oid);
	}
	
	
}





































